var Action = require("../apiaction");

exports.userAPI = function(router) {
    /** ----------------------课程管理--咨询分类-----------------------*/
        //咨询分类列表
    router.all('/ct/act/consultationClassification',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }

        var params = {page:page,rows:rows,method:'GET',listType:'0'};

        Action.send(req, res,"articlecates/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //分类增加
    router.all('/ct/act/classification_add',function(req,res){
        var params={};
        params["method"]="POST";
        params["article_cate_name"] = req.param("article_cate_name");//分类

        Action.send(req, res,"articlecates",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获取分类详情
    router.all('/ct/act/class_detail',function(req,res){
        var article_cate_id = req.param("article_cate_id");

        Action.send(req, res,"articlecates/"+article_cate_id,{method:'GET'},function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //分类编辑
    router.all('/ct/act/classification_edit',function(req,res){
        var params={};
        params["method"]="PUT";
        params["article_cate_name"] = req.param("article_cate_name");//分类名称
        var article_cate_id = req.param("article_cate_id");

        Action.send(req, res,"articlecates/"+article_cate_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //分类删除
    router.all('/ct/act/consultationClassification_delete', function(req,res){
        var params = {};
        params["method"] = "DELETE";
        article_cate_id = req.param("article_cate_id");

        Action.send(req,res,"articlecates/"+article_cate_id,params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    /** ----------------------课程管理--咨询文章-----------------------*/
    //咨询文章列表
    router.all('/ct/act/consultationArticle',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        var article_title = req.param("article_title");
        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        var params = {page:page,rows:rows,method:'GET',listType:"0"};
        if(article_title!=''){
            params.article_title = article_title;
        }
        Action.send(req, res,"articles/list",params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //增加
    router.all('/ct/act/acticle_add',function(req,res){
        var params={};
        params["method"]="POST";
        params["article_title"] = req.param("acticle_title");//标题
        params["article_author"] = req.param("acticle_actor");//作者
        params["article_body"] = req.param("content");//内容
        params["article_cover"] = req.param("cover");//封面
        params["article_cate_id"] = req.param("category");//分类
        params["train_id"] = req.param("train");//课程

        Action.send(req, res,"/articles",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获取文章详情
    router.all('/ct/act/article_detail',function(req,res){
        var params = {};
        var article_id = req.param("article_id");
        params["method"] = "GET";

        Action.send(req, res,"articles/"+article_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json.data));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //编辑
    router.all('/ct/act/article_edit',function(req,res){
        var article_id = req.param("article_id_gb");
        var params={};
        params["method"]="PUT";
        params["article_title"] = req.param("acticle_title");//标题
        params["article_author"] = req.param("acticle_actor");//作者
        params["article_body"] = req.param("content");//内容
        params["article_cover"] = req.param("cover");//封面
        params["article_cate_id"] = req.param("category");//分类
        params["train_id"] = req.param("train");//课程

        Action.send(req, res,"articles/"+article_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //删除
    router.all('/ct/act/article_delete', function(req,res){
        var params = {};
        params["method"] = "DELETE";
        var article_id = req.param("article_id");

        Action.send(req,res,"articles/"+article_id,params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    /** ----------------------课程管理--资料库管理-----------------------*/
        //资料库管理列表
    router.all('/ct/act/databaseManagement',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        var asset_name = req.param("asset_name");
        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }

        var params = {page:page,rows:rows,method:'GET',listType:'0',asset_name:asset_name};

        Action.send(req, res,"assets/list",params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //上传文件
    router.all('/ct/act/database_upload',function(req,res){
        var asset_name = req.param("asset_name");
        var asset_url = req.param("asset_url");
        var formatter = req.param("formatter");
        var size      = req.param("size");

        var params = {asset_name:asset_name,asset_url:asset_url,formatter:formatter,size:size,method:"POST"};
        Action.send(req,res,"assets",params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //删除
    router.all('/ct/act/data_delete', function(req,res){
        var params = {};
        params["method"] = "DELETE";
        var asset_id = req.param("asset_id");

        Action.send(req,res,"assets/"+asset_id,params,function(res,data){
            var json = JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    /** ----------------------用户管理-----------------------*/
        //获取用户列表
    router.all('/ct/act/user_list',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        var listType = req.param("listType");
        var keyword = req.param("keyword");
        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        var params = {page:page,rows:rows,method:'GET',listType:listType,keyword:keyword};
        Action.send(req, res,"/users/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //用户单条增加
    router.all('/ct/act/user_add',function(req,res){
        var params={};
        params["method"]="POST";
        params["user_type"] = req.param("user_type");//用户类型
        params["user_name"] = req.param("user_name");//名字
        params["user_mobile"] = req.param("user_mobile");//电话

        var user_gender            = req.param("user_gender");//性别
        var user_address           = req.param("user_address");//地址
        var user_mail              = req.param("user_mail");//邮箱
        var user_second_department = req.param("user_second_department");//二层
        var user_third_department  = req.param("user_third_department");//三层
        var user_post              = req.param("user_post");//职位
        var user_company           = req.param("user_company");//公司
        if(user_gender !="-1"){
            params.user_gender = user_gender;
        }
        if(user_address !=""){
            params.user_address = user_address;
        }
        if(user_mail != ""){
            params.user_mail = user_mail;
        }

        if(params.user_type == 0){
            if(user_second_department !=""){
                params.user_second_department = user_second_department;
            }
            if(user_third_department !=""){
                params.user_third_department = user_third_department;
            }
        }else {
            if(user_post !=""){
                params.user_post = user_post;
            }
            if(user_company !=""){
                params.user_company = user_company;
            }
        }

        Action.send(req, res,"/users",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //用户批量上传
    router.all('/ct/act/user_upload',function(req,res){
        var file = req.param("file");//获取url

        var params = {file:file};

        Action.send(req,res,"/users/importUsers",params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //获取用户详情
    router.all('/ct/act/user_detail',function(req,res){
        var params = {};
        var user_id = req.param("user_id");
        params["method"] = "GET";
        params.user_id = user_id;

        Action.send(req, res,"/users/"+user_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json.data));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //用户信息编辑
    router.all('/ct/act/user_edit',function(req,res){
        var user_id = req.param("user_id");
        var params={};
        params["method"]="PUT";
        params["user_type"] = req.param("user_type");//用户类型
        params["user_name"] = req.param("user_name");//名字
        params["user_gender"] = req.param("user_gender");//性别
        params["user_mobile"] = req.param("user_mobile");//电话
        params["user_address"] = req.param("user_address");//地址
        params["user_mail"] = req.param("user_mail");//邮箱

        if(params.user_type == 0){
            params["user_second_department"] = req.param("user_second_department");//二层
            params["user_third_department"] = req.param("user_third_department");//三层
        }else {
            params["user_post"] = req.param("user_post");//职位
            params["user_company"] = req.param("user_company");//公司
        }
        params.user_id = user_id;
        Action.send(req, res,"/users/"+user_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //用户删除
    router.all('/ct/act/user_delete', function(req,res){
        var params = {};
        params["method"] = "DELETE";
        var user_id = req.param("user_id");
        params.user_id  =user_id;

        Action.send(req,res,"/users/"+user_id,params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    /** ----------------------小组管理-----------------------*/
    //小组管理
    router.all('/ct/act/groupManagement',function(req,res){
        var params={};
        params["method"]="GET";

        Action.send(req, res,"teams/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //小组增加
    router.all('/ct/act/team_add',function(req,res){
        var params={};
        params["method"]="POST";
        params["team_name"] = req.param("team_name");//分类

        Action.send(req, res,"/teams",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获取小组详情
    router.all('/ct/act/team_detail',function(req,res){
        var team_id = req.param("team_id");
        var params = {team_id:team_id,method:'GET'};

        Action.send(req, res,"/teams/"+team_id,params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //小组编辑
    router.all('/ct/act/team_edit',function(req,res){
        var params={};
        params["method"]="PUT";
        params["team_name"] = req.param("team_name");//分类名称
        var team_id = req.param("team_id");
        params.team_id = team_id;

        Action.send(req, res,"/teams/"+team_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //删除小组
    router.all('/ct/act/team_delete', function(req,res){
        var params = {};
        params["method"] = "DELETE";
        var team_id = req.param("team_id");
        params.team_id = team_id;
        Action.send(req,res,"/teams/"+team_id,params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //新增组员页面的list
    router.all('/ct/act/addMumber',function(req,res){
        var params={};
        params["method"]="GET";
        var team_id = req.param("team_id");
        params.team_id = team_id;
        Action.send(req, res,"teams/"+team_id+"/members",params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //新增组员
    router.all('/ct/act/mumber_add',function(req,res){
        var params={};
        params["method"]="POST";
        params["user_idString"] = req.param("user_idString");//分类
        params["team_id"] = req.param("team_id");//分类

        Action.send(req, res,"/teams/userJoin",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //删除组员
    router.all('/ct/act/mumber_delete', function(req,res){
        var params = {};
        params["method"] = "POST";
        var user_id = req.param("user_id");
        var team_id = req.param("team_id");
        params.team_id = team_id;
        params.user_id = user_id;
        Action.send(req,res,"/teams/userExit",params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //设置组长
    router.all('/ct/act/set_leader',function(req,res){
        var params = {};
        params["method"]="PUT";
        params.team_id = req.param("team_id");
        params.user_id = req.param("user_id");

        Action.send(req,res,"/teams/setLeader",params,function(res,data){
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //小组讨论
    router.all('/ct/act/panelDiscussion_list',function(req,res){
        var params={};
        params["method"]="GET";
        var page = req.param("page");
        var rows = req.param("rows");
        var listType = "0";
        params.page=page;
        params.rows=rows;
        params.listType=listType;
        var train_id = req.param("train_id");
        var section_type = req.param("section_type");
        var team_id = req.param("team_id");
        if(train_id == "-1"){
            train_id = "0";
        }
        if(team_id == "-1"){
            team_id = "0";
        }
        params["train_id"] = train_id;
        params["team_id"] = team_id;
        params["section_type"] = section_type;
        params["keyword"] = req.param("keyword");
        Action.send(req, res,"/teamtalks/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    /** ----------------------行动学习管理-----------------------*/

    //删除培训
    router.all('/train_delete',function(req,res){
        var params={};
        params["method"]="DELETE";
        var train_id = req.param("train_id");//培训课程id
        Action.send(req, res,"trains/"+train_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //新增培训
    router.all('/trainsAdd',function(req,res){
        var params={};
        params["method"]="POST";
        params["train_name"] = req.param("train_name");//培训课程名称
        params["train_start_time"] = req.param("train_start_time");//培训开始时间

        Action.send(req, res,"/trains",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //编辑修改培训
    router.all('/train_update',function(req,res){
        var params={};
        params["method"]="PUT";
        params["train_name"] = req.param("train_name");//培训课程名称
        params["train_start_time"] = req.param("train_start_time");//培训课程名称
        var train_id = req.param("train_id");//培训课程id
        Action.send(req, res,"trains/"+train_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //培训列表
    router.all('/trainsList',function(req,res){
        var params={};
        params["method"]="GET";
        var page = req.param("page");
        var rows = req.param("rows");
        var listType = "0";
        params.page=page;
        params.rows=rows;
        params.listType=listType;
        Action.send(req, res,"/trains/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //报告list
    router.all('/reportList',function(req,res){
        var params={};
        params["method"]="GET";
        var page = req.param("page");
        var rows = req.param("rows");
        var user_name = req.param("user_name");
        var train_id = req.param("train_id");
        params.page=page;
        params.rows=rows;
        params.user_name=user_name;
        params.train_id = train_id;
        Action.send(req, res,"/reports/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //报告增加
    router.all('/ct/act/report_add',function(req,res){
        var params={};
        params["method"]="POST";
        var user_id = req.param("user_id");
        var train_id = req.param("train_id");
        var report_body = req.param("report_body");
        var result = req.param("result");
        params = {user_id:user_id,train_id:train_id,report_body:report_body,result:result};

        Action.send(req, res,"/reports",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //报告删除
    router.all('/ct/act/report_delete',function(req,res){
        var params={};
        params["method"]="DELETE";
        var report_id = req.param("report_id");//报告id
        Action.send(req, res,"/reports/"+report_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获取报告详情
    router.all('/ct/act/report_detail',function(req,res){
        var params={};
        params["method"]="GET";
        params["listType"]=0;
        var report_id = req.param("report_id");//报告id
        params.report_id = report_id;

        Action.send(req, res,"/reports/detail",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //修改报告
    router.all('/ct/act/report_editor',function(req,res){
        var params={};
        var report_id = req.param("report_id");//报告id
        params["method"]="PUT";
        params["user_id"] = req.param("user_id");
        params["train_id"] = req.param("train_id");
        params["report_body"] = req.param("report_body");
        params["result"] = req.param("result");


        Action.send(req, res,"/reports/"+report_id,params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    /**-------------------------聊天管理-------------------------*/
    //获取聊天列表
    router.all('/ct/act/chatManagement_list',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");

        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        var params = {page:page,rows:rows,method:'GET'};
        params.user_name = req.param("user_name");
        params.article_title = req.param("article_title");
        params.comment_body = req.param("comment_body");
        Action.send(req, res,"/messages/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //查看详情
    router.all('/ct/act/chat_detail',function(req,res){
        var message_id = req.param("message_id");
        var params = {};
        params.method = "GET";
        params.message_id = message_id;

        Action.send(req,res,'/messages/'+message_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })
    //导出
    router.all('/ct/act/chat_export',function(req,res){
        var params = {method:"GET"};

        Action.send(req,res,'messages/export',params,function(){
            res.downloadFile(req.url,'',function(){

            })
        })

    })
    /**-------------------------评论文章模块-------------------------*/
    //评论列表
    router.all('/ct/act/comment_list',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");

        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        var params = {page:page,rows:rows,method:'GET',listType:'0'};
        params.user_name = req.param("user_name");
        params.article_title = req.param("article_title");
        params.comment_body = req.param("comment_body");
        Action.send(req, res,"/articlecomments/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //评论详情
    router.all('/ct/act/comment_detail',function(req,res){
        var article_comment_id = req.param("article_comment_id");
        var params = {method:'GET'};

        Action.send(req, res,"/articlecomments/"+article_comment_id,params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });
    //删除评论
    router.all('/ct/act/comment_delete',function(req,res){
        var params={};
        params["method"]="DELETE";
        var article_comment_id = req.param("article_comment_id");//评论id
        Action.send(req, res,"/articlecomments/"+article_comment_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //词汇新增
    router.all('/vocabularysAdd',function(req,res){
        var params={};
        params["method"]="POST";
        var train_id = req.param("train_id");
        var VocabularyList = req.param("VocabularyList");
        params.train_id=train_id;
        params.VocabularyList=VocabularyList;
        Action.send(req, res,"/vocabularys",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //词汇展示
    router.all('/vocabularysShow',function(req,res){
        var params={};
        params["method"]="GET";
        var train_id = req.param("train_id");
        params.train_id=train_id;
        Action.send(req, res,"/vocabularys/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //行动学习题目新增
    router.all('/subjectsAdd',function(req,res){
        var params={};
        params["method"]="POST";
        var train_id = req.param("train_id");
        var section_type = req.param("section_type");
        var studytestlist = req.param("studytestlist");
        var study_test_status=req.param('study_test_status');
        params.train_id=train_id;
        params.section_type=section_type;
        params.studytestlist=studytestlist;
        params.study_test_status=study_test_status;
        Action.send(req, res,"/subjects",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //行动学习题目列表
    router.all('/subjectsShow',function(req,res){
        var params={};
        params["method"]="GET";
        var train_id = req.param("train_id");
        var section_type = req.param("section_type");
        var listType=req.param("listType");
        params.train_id=train_id;
        params.section_type=section_type;
        params.listType=listType;
        Action.send(req, res,"/subjects/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //课程考核新增
    router.all('/questionsAdd',function(req,res){
        var params={};
        params["method"]="POST";
        var paper_id = req.param("paper_id");
        var question_status = req.param("question_status");
        var question_list=req.param("question_list");
        params.paper_id=paper_id;
        params.question_status=question_status;
        params.question_list=question_list;
        Action.send(req, res,"/questions",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //课程新增
    router.all('/papersAdd',function(req,res){
        var params={};
        params["method"]="POST";
        var paper_name = req.param("paper_name");
        params.paper_name=paper_name;
        Action.send(req, res,"/papers",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
   //课程列表
    router.all('/papersList',function(req,res){
        var params={};
        params["method"]="GET";
        var page = req.param("page");
        var rows = req.param("rows");

        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        params.listType=0;
        params.page=page;
        params.rows=rows;
        Action.send(req, res,"/papers/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //删除课程
    router.all('/papersDelete',function(req,res){
        var params={};
        params["method"]="DELETE";
        var paper_id = req.param("paper_id");
        Action.send(req, res,"/papers/"+paper_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

   //课程修改
    router.all('/papersUpdate',function(req,res){
        var params={};
        params["method"]="PUT";
        var paper_name = req.param("paper_name");
        var paper_id = req.param("paper_id");
        params.paper_name=paper_name;
        Action.send(req, res,"/papers/"+paper_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
   //新增试卷
    router.all('/questionsAdd',function(req,res){
        var params={};
        params["method"]="POST";
        var paper_id = req.param("paper_id");
        var question_status = req.param("question_status");
        var question_list = req.param("question_list");
        params.paper_id=paper_id;
        params.question_status=question_status;
        params.question_list=question_list;
        Action.send(req, res,"/questions",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //试卷列表
    router.all('/questionsList',function(req,res){
        var params={};
        params["method"]="GET";
        var paper_id = req.param("paper_id");
        var listType = req.param("listType");
        var page = req.param("page");
        var rows = req.param("rows");

        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        params.paper_id=paper_id;
        params.listType=listType;
        params.page=page;
        params.rows=rows;
        Action.send(req, res,"/questions/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //管理员登陆
    router.all('/adminLogin',function(req,res){
        var params={};
        params["method"]="POST";
        var user_mobile = req.param("user_mobile");
        var user_password = req.param("user_password");
        params.user_mobile=user_mobile;
        params.user_password=user_password;
        Action.send(req, res,"users/adminlogin",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //考核报告列表
    router.all('/resultsList',function(req,res){
        var params={};
        params["method"]="GET";
        var paper_id = req.param("paper_id");
        var page = req.param("page");
        var rows = req.param("rows");

        if(!page){
            page=1;
        }
        if(!rows){
            rows=10;
        }
        params.paper_id=paper_id;
        params.page=page;
        params.rows=rows;
        Action.send(req, res,"/results/list",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //考核报告详情
    router.all('/results',function(req,res){
        var params={};
        params["method"]="GET";
        var results_id = req.param("results_id");
        params.paper_name=paper_name;
        Action.send(req, res,"/results/"+results_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //修改报告
    router.all('/resultsUpdate',function(req,res){
        var params={};
        params["method"]="PUT";
        var result_id = req.param("result_id");//报告id
        var result = req.param("result");//分数
        var status = req.param("status");//状态
        params.result=result;
        params.status=status;
        Action.send(req, res,"/results/"+result_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

//学习汇总列表
    router.all('/overviewsList',function(req,res) {
        var params = {};
        params["method"] = "GET";
        var listType = req.param("listType");
        var page = req.param("page");
        var rows = req.param("rows");

        if (!page) {
            page = 1;
        }
        if (!rows) {
            rows = 10;
        }
        params.listType = listType;
        params.page = page;
        params.rows = rows;
        Action.send(req, res, "/users/overviews", params, function (res, data) {
            var json = JSON.parse(data);
            if (json.code == 0) {
                res.status(200).send(JSON.stringify(json));
            } else {
                res.status(200).send(data);
            }
        })
    });

    //学习汇总详情
    router.all('/overviewsShow',function(req,res) {
        var params = {};
        params["method"] = "GET";
        var user_id = req.param("user_id");
        Action.send(req, res, "users/"+user_id+"/overview", params, function (res, data) {
            var json = JSON.parse(data);
            if (json.code == 0) {
                res.status(200).send(JSON.stringify(json));
            } else {
                res.status(200).send(data);
            }
        })
    });

    //学习汇总成绩修改
    router.all('/reportseeExamUpdate',function(req,res) {
        var params = {};
        params["method"] = "PUT";
        var user_id = req.param("user_id");
        var train_id = req.param("train_id");
        var exam_result = req.param("exam_result");
        params.user_id=user_id;
        params.train_id=train_id;
        params.exam_result=exam_result;
        Action.send(req, res, "/reports/exam", params, function (res, data) {
            var json = JSON.parse(data);
            if (json.code == 0) {
                res.status(200).send(JSON.stringify(json));
            } else {
                res.status(200).send(data);
            }
        })
    });

    //轮播图list
    router.all('/ct/act/banner_list',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var listType = "0";
        var method = "GET";
        var param={page:page,rows:rows,listType:listType,method:method};
        Action.send(req,res,'/banners/list',param,function(res,data){
            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });


    //新增轮播图
    router.post('/ct/act/banner_add',function(req,res){
        var banner_url = req.param("banner_url");
        var params={banner_url:banner_url,method:"POST"};
        Action.send(req, res,"/banners",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    // 删除轮播图
    router.post('/ct/act/banner_delete',function(req,res){
        var banner_id = req.param("banner_id");
        Action.send(req, res,"banners/"+banner_id,{method:"DELETE"},function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //修改轮播图状态
    router.post('/ct/act/banner_change',function(req,res){
        var banner_id = req.param("banner_id");
        var type = req.param("type");
        var params={type:type,method:"PUT"};
        Action.send(req, res,"banners/"+banner_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

}

